package com.grf.hadoop.combine_text_input_format;

import com.grf.hadoop.word_count.MyMapper;
import com.grf.hadoop.word_count.MyReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.lib.CombineFileInputFormat;
import org.apache.hadoop.mapred.lib.CombineTextInputFormat;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import java.io.IOException;

public class CombineDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf);
        job.setJarByClass(CombineDriver.class);
        job.setMapperClass(MyMapper.class);
        job.setReducerClass(MyReducer.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);


        //设置输入格式类型
        job.setInputFormatClass(CombineTextInputFormat.class);
        //设置每个切片的大小，根据实际小文件的大小设置
        CombineFileInputFormat.setMaxInputSplitSize(job, 2048);
        //使用set会报错
        //FileInputFormat.setInputPaths(job, new Path
        //       ("C:\\Users\\Administrator\\Desktop\\大数据\\data"));
        //要使用add
        FileInputFormat.addInputPath(job, new Path
                ("C:\\Users\\Administrator\\Desktop\\大数据\\data"));

        FileOutputFormat.setOutputPath(job, new Path
                ("C:\\Users\\Administrator\\Desktop\\output"));
        job.waitForCompletion(true);
    }
}
